<?php
  session_start();
  echo $_SESSION["statusMsg"];
  $dbUtilObj = new DBUtil();
  $commonUtilObj = new CommonUtil();
  $requestAction = $_REQUEST['action'];
  $buttom = "addLanguageSegment";
  $formAction = "$admin_url/action.php?pageId=3&action=addNew"; 
   if ($requestAction == "edit"){
     $editData = $dbUtilObj->getRecordById(LANSEGMENT,$_REQUEST['id']);
	 $formAction = "$admin_url/action.php?pageId=3&action=update&id=".$_REQUEST['id']; 
	   $buttom = "updateLanguageSegment";
	 }
    
?>
  <?php
     if ($requestAction == "edit")
	   echo "Seg Id ".$editData->seg_id;
  ?>
<form action="<?=$formAction?>" method="post">
   Choose Language:
      <select name="lan_id">
	     <?php
		   echo $commonUtilObj->getOptionValue(LANMASTER,"lan_id","lan_name");	  
		 ?>
	  </select>
	  <br />
   Segment Name :- <input type="text" name="seg_name" id="seg_name"  value="<?=$editData->seg_name?>"/> <br  />
   Segment Count :- <input type="text" name="seg_count" id="seg_count" value="<?=$editData->seg_count?>" /> <br  />
   Segment Desc :- <input type="text" name="seg_desc" id="seg_desc" value="<?=$editData->seg_desc?>" /> <br  />
   <input type="submit" value="<?=$buttom?>" name="addLanSeg" onclick="this.value='Processing....'"  />
</form>
<hr  />
Display All Language Segments <br  />
<?php
   $lanJSON = $dbUtilObj->getAllRecords(LANSEGMENT);
   if ($lanJSON != "")
   {
?>
<script>
 function deleteURL(id)
 {
   var url = "<?=$admin_url?>/action.php?pageId=3&action=delete&id=";
   if (confirm ("Confirm Delete"))
   {
     url += id;
	 window.location.href=url;
   }
 }
  function editURL(id)
  { 
   window.location.href="<?=$admin_url?>/index.php?pageId=3&action=edit&id="+id;
   }
   
</script>
<table width="95%" id="viewTable" cellpadding="0" cellspacing="0" border="0" class="display">
    <thead>
  <tr>
  <?php foreach($lanJSON[0] as $key=>$value){ ?>
 
    <th> <?php echo $key; ?></th>
   <?php } ?>
    <th>Action</th>
  </tr>
  </thead>
  <tbody>
  <?php foreach($lanJSON as $key2=>$value)
  { 
   $var = 0;
  ?>
  
  <tr>
  	<?php foreach($value as $key1=>$tab){ ?>
    <td>
	<?php 
	 if ($var == 0)
	    $id = $tab;
     $var ++;
	echo $tab; 
	?>
	</td>
    <?php } ?>
	  <td>
	  <img src="<?=$admin_url?>/media/images/edit-icon.gif" style="cursor:pointer;" onclick="editURL(<?=$id?>)"/>
	  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	  <img src="<?=$admin_url?>/media/images/del-icon.gif" style="cursor:pointer;" onclick="deleteURL(<?=$id?>)"/>
	  </td>	
  </tr>
  <?php } ?>
  </tbody>
</table>
<?php }
 else{
   echo "No Data Availble";
 }
 ?>
